// (c) Copyright 2011 Borja Sánchez Zamorano (BSD License)
// feedback: borsanza AT gmail DOT com

#ifndef AppleRemote_h
#define AppleRemote_h

class RemoteKey {
	private:
		unsigned short id;
		unsigned char command;
		unsigned char remoteId;
		unsigned long lastTime;
		unsigned int count;

	public:
		RemoteKey();
		void decode(unsigned long command);

		unsigned short getId() const;
		unsigned char getCommand() const;
		unsigned char getRemoteId() const;
		bool isRepeatingKey() const;
		bool isKey() const;
		bool isAppleRemote() const;
		unsigned long getLastTime() const;
		unsigned int getCount() const;
		bool isDoubleButton() const;
		bool isSpecialKey() const;

		void updateTime();
		void setRepeatingKey();
		void setNoKey();
		void resetCount();
		void incCount();
		
		const char * getName() const;
		const char * getCodeLibrary() const;
		void verbose(bool endline);
};

class IRrecv;

class AppleRemote {
	private:
		RemoteKey actualKey;

		IRrecv *irrecv;

		bool blink13;
		bool enableLog;
		bool lastState;
		unsigned long lastTime;
		unsigned long outputSpeed;
		int linkedRemoteId;
		int irpin;
		int ledPin;

		void sendCommand();
		void printCommand(const char * value, bool pressed);
		bool acceptRemote() const;
		void setLinkedRemoteId(int linkedRemoteId);
		void loadLinkedRemoteId();

	public:
		AppleRemote();
		void setOutputSpeed(unsigned long speed);
		void setIRPin(int irpin);
		void setLedPin(int ledPin);
		void setBlink13Mode(bool enabled);
		void setLogMode(bool enabled);
		void init();
		void loop();
};

#endif
